#include <CString>
#include <stdio.h>

/* CString test */
int test_cstring()
{
	{
		CString s1("dog"), s2("f"), s3("dog"); 
		assert(s1 == "dog");
		assert(s2 == 'f');
		assert(s1 == s3);
	}

	{
		CString s1("cat"), s2("cats"), s3("dogs");
		assert(s1 < "dog");
		assert(s1 < "cats");
		assert(s2 < "cats and dogs");
		assert(s2 < s3);   
	}

	{
		CString s = "cstring";
		printf("I'm printing cstring:%s done\n", s.GetString());
	}

	{
		CString s("abcdef");
		assert(s.FindOneOf("xd") == 3); // 'd' is first match   
		assert(s.Find('c') == 2);
		assert(s.Find("de") == 3);
		assert(s.Mid(2, 3) == "cde");
		assert(s.Right(2) == "ef");
		assert(s.Left(2) == "ab"); 
	}

	{
		CString str("The waves are still");
		int n = str.Find('e');
		assert(n == 2);
	}

	{
		CString str = "  Soccer is best ";
		assert(str.Trim(' ') == "Soccer is best");
		str="\n";
		str.Trim("\n");
		assert(str == "");
	}

	{
		CString str("%First   Second##Third");
		CString resToken;
		int curPos = 0;

		resToken= str.Tokenize("% #",curPos);
		int i=0;
		while (resToken != "")
		{
			printf("res=%s\n", resToken.GetString());
			if (i==0)
				assert(resToken == "First");
			else if (i==1)
				assert(resToken == "Second");
			else if (i==2)
				assert(resToken == "Third");
			else
				assert(0);
			i++;
			resToken = str.Tokenize("% #", curPos);
		};   
	}

	{
		CString s("ABCdE");
		assert(s.MakeLower() == "abcde");   
	}

	{
		CString s;
		assert(s == "");
		CString c;
		c.Format("%c", 'H');
		s.Append(c);
		assert(s == "H");
		printf("=> %s\n", s.GetString());
	}

	printf("CString tests are ok\n");
	return 0;
}

int main()
{
	test_cstring();
	return 0;
}
